/**
 * Copyright (C) 2015-2018 IQIYI
 * All rights reserved.
 *
 * AUTHOR(S)
 * 王海斌
 *   E-mail: wanghaibin@qiyi.com
 * 
 * VERSION
 *   Tue 03 Apr 2018 04:49:57 PM CST
 */

#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


int main(int argc, char *argv[])
{
    if(argc!=2) {
        printf("usage: %s file\n",argv[0]);
    }
    int iRet = access(argv[1], X_OK);
    printf("X_OK ret=%d, err=%s\n", iRet, strerror(errno));
    errno=0;
    iRet = access(argv[1], W_OK);
    printf("W_OK ret=%d, err=%s\n", iRet, strerror(errno));
    iRet = 0;
    int fd = open( "/data2/www/whb.dat",
            O_WRONLY | O_CREAT | O_APPEND,
            S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
            | S_IROTH | S_IWOTH );
    if(fd<0) {
        printf("open failed. ret=%d, err=%s\n", iRet, strerror(errno));
    } else {
        close(fd);
    }

    return 0;
}
